package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 查看当前添加的对象是否在购物车里
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新商品数量
     * @param shoppingCart
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 添加购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车商品
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteById(Long currentId);

    /**
     * 根据dishid查购物车
     * @param dishId
     * @return
     */
    @Select("select * from shopping_cart where dish_id=#{dishId}")
    ShoppingCart getByDishId(Long dishId);

    /**
     * 根据套餐id查购物车
     * @param setmealId
     * @return
     */
    @Select("select * from shopping_cart where setmeal_id=#{setmealId}")
    ShoppingCart getBySetmealId(Long setmealId);

    /**
     * 删除单个购物车选项
     * @param shoppingCart1
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void delete(ShoppingCart shoppingCart1);
}
